<?php
/**
 * 【炫】 
 *
 * @author D
 * @url http:// blog.donghy.cn
 */ 
defined('IN_IA') or exit('Access Denied');
!defined('D_PATH') && define('D_PATH', '../addons/xuan_zyy/public/');
require_once 'inc/functions.php'; 
class Xuan_zyyModuleSite extends WeModuleSite {
	public function __construct(){
       // m('member')->checkMember();
	}
	public function createMobileUrl($do, $query = array(), $noredirect = true)
    {
        global $_W, $_GPC;
        $do = explode('/', $do);
        if (isset($do[1])) {
            $query = array_merge(array(
                'p' => $do[1]
            ), $query);
        }
        if (empty($query['mid'])) {
            $mid = intval($_GPC['mid']);
            if (!empty($mid)) {
                $query['mid'] = $mid;
            }
        }
        return $_W['siteroot'] . 'app/' . substr(parent::createMobileUrl($do[0], $query, true), 2);
    }
    public function createWebUrl($do, $query = array())
    {
        global $_W;
        $do = explode('/', $do);
        if (count($do) > 1 && isset($do[1])) {
            $query = array_merge(array(
                'p' => $do[1]
            ), $query);
        } 
        return $_W['siteroot'] . 'web/' . substr(parent::createWebUrl($do[0], $query, true), 2);
    }
    public function config(){
        global $_W;
        $sql = 'SELECT `settings` FROM ' . tablename('uni_account_modules') . ' WHERE uniacid=:uniacid and `module` = :module';
        $settings = pdo_fetchcolumn($sql, array(':uniacid'=>$_W['uniacid'] ,':module' => 'xuan_zyy'));
        $settings = iunserializer($settings);
        return $settings;
    }


    public function payResult($params) {
        global $_W;
        $out_trade_no=$params['tid'];
        $money=$params['fee'];
        $trade_no=$params['uniontid'];
        $config=$this->config();
        if ($params['result'] == 'success' && $params['from'] == 'notify') {
            $order=explode('-',$out_trade_no);
            if($order[0]=='ZX'){

                try {
                    pdo_begin();
                    $order=pdo_fetch(' select * from  '.tablename('xuan_zy_zxorder').' where out_trade_no=:tid',array(':tid'=>$out_trade_no));
                    //$zx=pdo_fetch(' select * from  '.tablename('xuan_zy_zxsetting').' where id=:id',array(':id'=>$order['zxid']));
                    if ( $order['money']==$money && $order['pay']==0 ) {

                        pdo_update('xuan_zy_zxorder', array('status'=>2,'pay'=>1), array('out_trade_no' => $out_trade_no));

                    }
                    pdo_commit();
                } catch (Exception $e) {
                    pdo_rollback();
                }


            }



        }
        if ($params['from'] == 'return') {
            if ($params['result'] == 'success') {

                message('支付成功！', $this->createMobileUrl('person'), 'success');
            } else {
                message('支付失败！', $this->createMobileUrl('person'), 'error');
            }
        }


    }
 


}